<?php
/**
 * 
 * 管理员权限类
 * @author Administrator
 *
 */
class osgh_admin_id_module_tbl_cls extends pl_db_opt_cls
{
	/**
	 * 构造函数
	 */
	public function __construct()
	{
		global $_db_name;
		$this->setDbName($_db_name);
		$this->setTblName('osgh_admin_id_module_tbl');
	}
	
	/**
	 * 
	 * 增加管理员管理模块 ...
	 * @param array $data
	 */
	public function addAdminModule($data)
	{
		return $this->insert($data, 'IGNORE');
	}
	
	
	/**
	 * 
	 * 删除管理员模块
	 * @param int $admin_id
	 * @param int $module_id
	 */
	public function delAdminModule($module_id = 0, $admin_id = 0)
	{
		$sp_str = '';
		$where_str = '';
		$module_id = intval($module_id);
		
		if ($module_id > 0 )
		{
			$where_str .= ' module_id='.$module_id;
		}
		if ($admin_id > 0)
		{
			strlen($where_str) > 0 ? $sp_str = ' AND' : $sp_str = '';
			$where_str .= $sp_str.' admin_id='.$admin_id;
		}
		return $this -> delete($where_str);
	}
	
	
	/**
	 * 获取管理员模块列表
	 * 
	 * @param bool $b_select_count
	 * @param string $where_str    查询条件
	 * @param string $order_by
	 * @param string $limit
	 * @return array
	 */
	public function getAdminIdModuleList($b_select_count = false, $where_str = '', $order_by = '', $limit = '')
	{
	  
		$sql = "SELECT * FROM {$this->db_name}.{$this->tbl_name}";
		
		$sql_where = '';
		$sql_where_sp = '';
		
		if( strlen($where_str) > 0 )
		{
			$sql_where_sp = strlen($sql_where)>0?' AND ':'';
			$sql_where = $sql_where . $sql_where_sp . $where_str;
		}
		
		if ( strlen($sql_where) > 0 )
		{
			$sql .= " WHERE " . $sql_where;
		}
		
		if ( $b_select_count == true )
		{
			//统计记录数
			$tmp = $this->getList($b_select_count, $sql);
			return $tmp;
		}		
		return $this->getList($b_select_count, $sql, $order_by, $limit);
	}
	
	/**
	 * 
	 * 执行SQL语句
	 * @param array data
	 */
	public function queryAdminModule($data)
	{
	   $sql = "INSERT INTO  {$this->db_name}.{$this->tbl_name} (`admin_id` ,`module_id`)VALUES ".$data;
	  
	   return $this->query($sql);
	}
}